package org.esgi.dao;

import java.io.File;
import java.util.List;

import org.esgi.model.interfaces.IHistory;
import org.esgi.repository.impl.XMLHistoryRepository;
import org.esgi.repository.interfaces.IHistoryRepository;

public class HistoryDao implements IHistoryRepository
{
	private static HistoryDao sharedHistoryDao_ = null;
	
	private IHistoryRepository historyRepository_;
	
	public static HistoryDao getSharedHistoryDao()
	{
		if(HistoryDao.sharedHistoryDao_ == null)
			HistoryDao.sharedHistoryDao_ = new HistoryDao();
		return HistoryDao.sharedHistoryDao_;
	}
	
	private HistoryDao() {}

	public void setDirectory(File dir)
	{
		this.historyRepository_ = new XMLHistoryRepository(dir);
	}
	
	@Override
	public Boolean saveHistory(IHistory anHistory)
	{
		return this.historyRepository_.saveHistory(anHistory);
	}

	@Override
	public Boolean removeHistory(IHistory anHistory)
	{
		return this.historyRepository_.removeHistory(anHistory);
	}

	@Override
	public IHistory getHistoryWithId(String anId) 
	{
		return this.historyRepository_.getHistoryWithId(anId);
	}
	
	@Override
	public File getFileHistoryWithId(String anId) 
	{
		return this.historyRepository_.getFileHistoryWithId(anId);
	}

	@Override
	public IHistory getLastHistory() 
	{
		return this.historyRepository_.getLastHistory();
	}
	
	@Override
	public File getLastFileHistory() 
	{
		return this.historyRepository_.getLastFileHistory();
	}
	
	@Override
	public List<IHistory> getAllHistories()
	{
		return this.historyRepository_.getAllHistories();
	}
}
